/**
 * 
 */
package biz.innovasoft.nodb.transaction;

import static biz.innovasoft.nodb.matchers.InstanceOf.instanceOf;
import static org.hamcrest.CoreMatchers.allOf;

import java.util.Date;
import java.util.List;

import org.hamcrest.Matcher;
import org.prevayler.Prevayler;

import biz.innovasoft.nodb.UpdateableList;
import biz.innovasoft.nodb.impl.GenericRepository;
import biz.innovasoft.nodb.query.Tuple;
import biz.innovasoft.nodb.util.ArrayUpdateableList;

/**
 * 
 * @author Diego Miranda
 *
 */
public class GetAllQueryMatcher extends BaseQuery {

	protected final Matcher<?> matcher;
	protected final Class<?> clazz;
	protected final boolean strict;
	
	@SuppressWarnings("unchecked")
	public GetAllQueryMatcher (Prevayler prevayler, Class<?> clazz, Matcher<?> matcher, boolean strict) {
		super (prevayler);
		this.clazz = clazz;
		if (matcher == null) {
			this.matcher = instanceOf(clazz, strict);
		} else {
			this.matcher = allOf(instanceOf(clazz, strict),(Matcher)matcher);
		}
		this.strict = strict;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Object query(GenericRepository repository, Date executionTime) throws Exception {
		List<Tuple> tuples = repository.getAll (matcher, true);
		UpdateableList ulist = new ArrayUpdateableList(prevayler, tuples);
		return ulist;
	}
	
	

}
